//C09:Paste.cpp
// {L} Vendor
// Fixing a mess with MI.
#include <iostream>
#include "Vendor.h"
using namespace std;

// Repair Vendor interface
class MyBase
{
    public:
        virtual void v() const = 0;
        virtual void f() const = 0;
        // New interface function:
        virtual void g() const = 0;
        virtual ~MyBase() { cout << "~MyBase()" << endl; }
};

class Paste1 : public MyBase, public Vendor1
{
    public:
        void v() const
        {
            cout << "Paste1::v()" << endl;
            Vendor1::v();
        }

        void f() const
        {
            cout << "Paste1::f()" << endl;
            Vendor1::f();
        }

        void g() const
        {
            cout << "Paste1::g()" << endl;
        }

        ~Paste1() 
        {
            cout << "~Paste1()" << endl;
        }
};

int main(void)
{
    Paste1& p1p = *new Paste1;
    MyBase& mp = p1p;    // Upcast
    cout << "calling f()" << endl;
    mp.f();   // Right behavior
    cout << "calling g()" << endl;
    A(p1p);   // Same old behavior
    cout << "calling A(p1p)" << endl;
    B(p1p);   // Same old behavior
    cout << "delete mp" << endl;
    // Deleting a reference to a heap object:
    delete &mp;    // Right behavior
}